<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'qvmapping-form',
	'enableAjaxValidation'=>false,
)); ?>


	<?php echo $form->errorSummary($model); ?>
        <fieldset class="box" id="accordion">
            <legend>Basics</legend>
            <table>
            <tr class="row">
                    <td><?php echo $form->labelEx($model,'qvm_docName'); ?>
                    </td><td><?php echo $form->textField($model,'qvm_docName',array('size'=>50,'maxlength'=>150)); ?>
                    <?php echo $form->error($model,'qvm_docName'); ?></td>
            </tr>

            <tr class="row">
                <td>
		<?php echo $form->labelEx($model,'name'); ?>
		</td><td><?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'name'); ?>
                </td>
            </tr>
            <tr class="row">
		<td><?php echo $form->labelEx($model,'unique'); ?>
		</td><td><?php echo $form->checkBox($model,'unique'); ?>
                    <?php echo $form->error($model,'unique'); ?>
                    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>'button')); ?>
                </td>
            </tr>

            </table>
        </fieldset>

        <fieldset class="box">
            <legend>Mapping</legend>
        <table>
        <tr class="row">
            <td>
		<?php echo CHtml::ajaxButton('load Fields',
                        CController::createUrl('loadFields'),
                        array(
                                'type'=>'POST',
                                'update'=>'#Qvmapping_qvf_id_from',
                             ),
                        array(
                                'class'=>'button',
                             )
                        ); ?>
            </td>
            <td colspan="2" rowspan="2">
<?php
        $myPassModel = Qvfields::model();
        $myPassModel->qvf_docName = strtoupper($model->qvm_docName);
        echo $this->renderPartial('//qvfields/_form', array('model'=>$myPassModel),true);
?>
            </td>
            <td>
		<?php echo CHtml::ajaxButton('load Fields',
                        CController::createUrl('loadFields'),
                        array(
                                'type'=>'POST',
                                'update'=>'#Qvmapping_qvf_id_to',
                             ),
                        array(
                                'class'=>'button',
                             )
                        ); ?>
            </td>
        </tr>
        <tr class="row">
            <td>
                <?php
                    echo $form->dropdownList($model,'qvf_id_from',
                        CHtml::listData(Qvfields::model()->findAll("qvf_docName = :qvf_docName",array(":qvf_docName"=>strtoupper($model->qvm_docName))),'qvf_id','qvf_fieldName')
                        ); ?>
                <?php echo $form->error($model,'qvf_id_from'); ?>
                <br/>
                <?php echo CHtml::ajaxLink('load from values',
                        CController::createUrl('loadValues'),
                        array(
                                'type'=>'POST',
                                'update'=>'#id_from_values',
                                'data'=>array(
                                    'id'=>$model->qvf_id_from,
                                    'docName'=>strtoupper($model->qvm_docName),
                                ),
                             )                        
                        ); ?>
            </td>
            <!-- kommt von oben /-->
            <td>
		<?php echo $form->dropdownList($model,'qvf_id_to',
                        CHtml::listData(Qvfields::model()->findAll("qvf_docName = :qvf_docName",array(":qvf_docName"=>strtoupper($model->qvm_docName))),'qvf_id','qvf_fieldName')
                        ); ?>
                <?php echo $form->error($model,'qvf_id_to'); ?>
                <?php echo CHtml::ajaxLink('load to values',
                        CController::createUrl('loadValues'),
                        array(
                                'type'=>'POST',
                                'update'=>'#id_to_values',
                                'data'=>array(
                                    'id'=>$model->qvf_id_to,
                                    'docName'=>strtoupper($model->qvm_docName),
                                ),
                             )
                          ); ?>
            </td>
        </tr>
        <tr>
            <td>

                <?php echo CHtml::hiddenField('act_id_from',0); ?>

    <?php
        $myValueModel = Qvvalues::model();
        $myValueModel->qvf_id = $model->qvf_id_from;
        echo $this->renderPartial('//qvvalues/_form', array('model'=>$myValueModel),true);
    ?>
                <div style="width:215px;height:200px;overflow: auto;background: #ffffff;z-index:0;border: 1px solid">

<?php

$itemsone = CHtml::listData(Qvvalues::model()->findAll('qvf_id = :qvf_id',array(':qvf_id'=>$model->qvf_id_from)),'qvv_id','qvv_fieldValue');

    $this->Widget('zii.widgets.jui.CJuiSelectable', array(
            'items'=>$itemsone,
            'id'=>'id_from_values',
            // additional javascript options for the draggable plugin
            'options'=>array(
                'selected'=>"js:function(event,ui){
                    $('#act_id_from').val(ui.selected.id);
                    $('#Notification').jnotifyAddMessage({
                        text: 'loading mapped QV Values...',
                        permanent: false,
                        showIcon: true
                    });
                    jQuery.ajax(
                        {
                            'type':'POST',
                            'url':'".Yii::app()->urlManager->createUrl('qvmapping/loadMaps')."',
                            'cache':false,
                            'data':jQuery(this).parents('form').serialize(),
                            'success':function(html){
                                jQuery('#result_tmp').html(html);
                            }
                    });
                }",
            ),
    ));

?>
</div>

            </td>
            <td>

                <?php echo CHtml::hiddenField('act_id_mapped',0); ?>

                <?php //echo CHtml::textField('filter_id_mapped','',array('size'=>17,'class'=>'searchwrapper')); ?>


<div style="width:180px;height:290px;overflow: auto;background: #ffffff;z-index:0;border: 1px solid">

<?php

    $this->Widget('zii.widgets.jui.CJuiSelectable', array(
            'items'=>array('0'=>'Select from...'),
            'id'=>'result_tmp',
            // additional javascript options for the draggable plugin
            'options'=>array(
                'start'=>"js:function(event,ui){
                                $('#act_id_mapped').val(0);
                            }",
                'selected'=>"js:function(event,ui){
                    var tempVal = $('#act_id_mapped').val();
                    $('#act_id_mapped').val(ui.selected.id + ',' + tempVal);
                }",
            ),
    ));

?>
</div>


            </td>
            <td>

                <?php echo CHtml::ajaxButton('<<',
                        CController::createUrl('addMapValues'),
                        array(
                                'type'=>'POST',
                                'update'=>'#result_tmp',
                             ),
                        array(
                                'class'=>'button',
                            )
                        ); ?>

                <?php echo CHtml::ajaxButton('>>',
                        CController::createUrl('delMapValues'),
                        array(
                                'type'=>'POST',
                                'update'=>'#result_tmp',
                             ),
                        array(
                                'class'=>'button',
                            )
                        ); ?>

            </td>
            <td>

                <?php echo CHtml::hiddenField('act_id_to',0); ?>

                <?php echo CHtml::textField('filter_id_to','',array('size'=>17,'class'=>'searchwrapper')); ?>


<div style="width:180px;height:265px;overflow: auto;background: #ffffff;z-index:0;border: 1px solid">

<?php

$itemsone = CHtml::listData(Qvvalues::model()->findAll('qvf_id = :qvf_id',array(':qvf_id'=>$model->qvf_id_to)),'qvv_id','qvv_fieldValue');

    $this->Widget('zii.widgets.jui.CJuiSelectable', array(
            'items'=>$itemsone,
            'id'=>'id_to_values',
            // additional javascript options for the draggable plugin
            'options'=>array(
                'start'=>"js:function(event,ui){
                                $('#act_id_to').val(0);
                            }",
                'selected'=>"js:function(event,ui){
                    var tempVal = $('#act_id_to').val();
                    $('#act_id_to').val(ui.selected.id + ',' + tempVal);
                }",
            ),
    ));

?>
</div>


            </td>
        </tr>

        </table>

        </fieldset>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

<?php $this->endWidget(); ?>

</div><!-- form -->